#-*- coding:utf-8 -*-

from django.http import HttpResponse
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.comments.models import Comment
from django.utils import simplejson


def home(request):
    return render(request, "index.html")

def upload(request):
    return render(request, "upload.html")

def json_comment(request):
    c = request.GET.get("c", "")
    if not c.isdigit():
        return HttpResponse(simplejson.dumps({'ret':'fail'}))

    obj = get_object_or_404(Comment, pk=int(c))
    ret = {
        'ret':'ok',
        'id':obj.id,
        'comment':obj.comment,
        'posttime':obj.submit_date.strftime("%Y-%m-%d %H:%M:%S")
    }

    return HttpResponse(simplejson.dumps(ret))

